package com.zd.escortaction.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zd.escortaction.domain.EscortAction;
import com.zd.escortaction.service.IEscortActionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护送人员操作动作记录Controller
 * 
 * @author fxiao
 * @date 2020-08-11
 */
@Controller
@RequestMapping("/escort/escortaction")
public class EscortActionController extends BaseController
{
    private String prefix = "escortaction";

    @Autowired
    private IEscortActionService escortActionService;

    @RequiresPermissions("escort:escortaction:view")
    @GetMapping()
    public String escortaction()
    {
        return prefix + "/escortaction";
    }

    /**
     * 查询护送人员操作动作记录列表
     */
    @RequiresPermissions("escort:escortaction:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EscortAction escortAction)
    {
        startPage();
        List<EscortAction> list = escortActionService.selectEscortActionList(escortAction);
        return getDataTable(list);
    }

    /**
     * 导出护送人员操作动作记录列表
     */
    @RequiresPermissions("escort:escortaction:export")
    @Log(title = "护送人员操作动作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EscortAction escortAction)
    {
        List<EscortAction> list = escortActionService.selectEscortActionList(escortAction);
        ExcelUtil<EscortAction> util = new ExcelUtil<EscortAction>(EscortAction.class);
        return util.exportExcel(list, "escortaction");
    }

    /**
     * 新增护送人员操作动作记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存护送人员操作动作记录
     */
    @RequiresPermissions("escort:escortaction:add")
    @Log(title = "护送人员操作动作记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EscortAction escortAction)
    {
        return toAjax(escortActionService.insertEscortAction(escortAction));
    }

    /**
     * 修改护送人员操作动作记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        EscortAction escortAction = escortActionService.selectEscortActionById(id);
        mmap.put("escortAction", escortAction);
        return prefix + "/edit";
    }

    /**
     * 修改保存护送人员操作动作记录
     */
    @RequiresPermissions("escort:escortaction:edit")
    @Log(title = "护送人员操作动作记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EscortAction escortAction)
    {
        return toAjax(escortActionService.updateEscortAction(escortAction));
    }

    /**
     * 删除护送人员操作动作记录
     */
    @RequiresPermissions("escort:escortaction:remove")
    @Log(title = "护送人员操作动作记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(escortActionService.deleteEscortActionByIds(ids));
    }
}
